<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item> <i class="el-icon-user"></i> 商家列表 </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-input v-model="name" placeholder="请输入商家姓名" class="handle-input mr10"  @keyup.enter.native="handleSearch"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
            </div>
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
            >
            
                <el-table-column prop="f_shopowner" label="商家姓名"></el-table-column>
                <el-table-column prop="f_shop_name" label="店铺名称"></el-table-column>
                <el-table-column prop="f_withDrawalScale" label="提现比例"></el-table-column>
                <el-table-column prop="f_phone" label="联系电话"></el-table-column>
                <el-table-column prop="moneys" label="营收总额"></el-table-column>
                <el-table-column prop="orderNums" label="订单数量"></el-table-column>
                <el-table-column prop="users" label="用户数量"></el-table-column>
                <el-table-column prop="memberUsers" label="会员数量"></el-table-column>
                <el-table-column prop="eqs" label="设备数量"></el-table-column>
                <el-table-column prop="eqIos" label="桌台数量"></el-table-column>
                <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" icon="el-icon-search" @click="handleEdit(scope.row)">查看</el-button>
                        <el-button type="text" icon="el-icon-setting" @click="Withdrawal(scope.row)">提现比例</el-button>
                        <el-button type="text" icon="el-icon-magic-stick" @click="Accredit(scope.row)">商家授权</el-button>
                        <el-button type="text" icon="el-icon-pie-chart" @click="Parameter(scope.row)">设置美团参数</el-button>
                    </template>
                   
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.page"
                    :page-size="query.pageNum"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
        <el-dialog title="设置美团参数" :visible.sync="Parametershow" width="30%">
            <el-form ref="form" :model="form" label-width="120px">
                <div style="display: flex">
                    <el-form-item label="美团key" >
                        <el-input placeholder="请输入美团key" v-model="key">{{ ratio }}</el-input>
                    </el-form-item>
                    
                </div>
                <div style="display: flex">
                <el-form-item label="美团secret" >
                        <el-input placeholder="请输入美团secret" v-model="secret">{{ ratio }}</el-input>
                    </el-form-item>
                </div>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="ParametersaveEdit()">确 定</el-button>
            </span>
        </el-dialog>

        <el-dialog title="提现比例" :visible.sync="Withdrawalshow" width="30%">
            <el-form ref="form" :model="form" label-width="70px">
                <div style="display: flex">
                    <el-form-item label="比例">
                        <el-input placeholder="请输入0~1之间的小数" v-model="ratio">{{ ratio }}</el-input>
                    </el-form-item>
                </div>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="shopsaveEdit()">确 定</el-button>
            </span>
        </el-dialog>
       
        <el-dialog title="查看弹窗" :visible.sync="editVisible" width="1000px" append-to-body>
            <el-form ref="form" :model="form" label-width="100px">
                <div style="display: flex">
                    <el-form-item label="商家姓名">
                        <el-input v-model="form.f_shopowner">{{ form.f_shopowner }}</el-input>
                    </el-form-item>
                    <el-form-item label="营收总额">
                        <el-input v-model="form.moneys">{{ form.moneys }}</el-input>
                    </el-form-item>
                    <el-form-item label="订单数量">
                        <el-input v-model="form.orderNums">{{ form.orderNums }}</el-input>
                    </el-form-item>
                </div>
                <div style="display: flex">
                    <el-form-item label="用户数量">
                        <el-input v-model="form.users">{{ form.users }}</el-input>
                    </el-form-item>
                    <el-form-item label="会员数量">
                        <el-input v-model="form.memberUsers">{{ form.memberUsers }}</el-input>
                    </el-form-item>
                    <el-form-item label="桌台数量">
                        <el-input v-model="form.eqIos">{{ form.eqIos }}</el-input>
                    </el-form-item>
                </div>
                <div style="display: flex">
                    <el-form-item label="商家头像">
                        <el-image
                            class="table-td-thumb"
                            :src="form.has_user ? form.has_user.f_headimgurl : ''"
                            :preview-src-list="[form.has_user ? form.has_user.f_headimgurl : '']"
                        ></el-image>
                    </el-form-item>
                    <el-form-item label="总开台时长" style="width: 247px">
                        <el-input v-model="form.long">{{ form.long }}</el-input>
                    </el-form-item>
                    <el-form-item label="会员卡数量" style="width: 247px">
                        <el-input v-model="form.memberCards">{{ form.memberCards }}</el-input>
                    </el-form-item>
                    <el-form-item label="优惠券数量" style="width: 247px">
                        <el-input v-model="form.coupons">{{ form.coupons }}</el-input>
                    </el-form-item>
                </div>
                <el-form-item label="设备列表">
                    <!-- <el-input v-model="form.eqs">{{ form.eqs }}</el-input> -->
                    <div v-for="(item,index) in form.eqs"  :key="index">
                        <div style="display: flex;">
                            <div style="width: 350px; height: auto; border: 1px solid rgb(238, 238, 238); padding-left: 20px;">
                                <div>设备名称: {{ item.f_equip_name }}</div>
                                <div>设备ID: {{ item.f_equip_id }}</div>
                                <div>设备编号: {{ item.f_union_code }}</div>
                                <div>设备平台标识: {{ item.f_equip_uuid }}</div>
                            </div>
                            <div style="width: 400px; height: auto; border: 1px solid rgb(238, 238, 238); padding-left: 20px;">
                            桌台列表:
                            <div v-for="(items,indexs) in item.has_io" :key="indexs">
                                桌台名称:{{ items.f_eq_id }} 桌台编号:{{ items.f_union_code }} 桌台状态:{{items.f_status == 0 ? '关闭' : '开台'}}
                            </div>
                        </div>
                        </div>
                       
                    </div>
                </el-form-item>
            </el-form>
        </el-dialog>
    </div>
</template>

<script>
import { shopList, shopInfo,setShopWithdrawalScale,setMtKey } from '../../../api/index';
export default {
    name: 'businesList',
    data() {
        return {
            query: {
                page: 1,
                pageNum: 10,
                type: 1 //商家列表
            },
            tableData: [],
            multipleSelection: [],
            delList: [],
            editVisible: false,
            Withdrawalshow:false,
            Parametershow:false,
            pageTotal: 0,
            form: {},
            name:'',
            ratio:'',
            shopId:'',
            m_shopId:'',
            secret:'',
            key:''
        };
    },
    created() {
        this.getData();
    },
    methods: {
       // 获取 easy-mock 的模拟数据
        getData() {
            shopList(this.query).then((res) => {
                console.log(res.data, '商家列表');
                this.tableData = res.data.list;
                this.pageTotal =  res.data.count || 50;
            });
        },
        //通过
        Applylist(e) {
            opApply({
                id: e.id,
                type: 1
            }).then((res) => {
                if (res.code == 0) {
                    this.$message.success('申请已通过');
                    this.getData();
                }
            });
        },
        // 触发搜索按钮
        handleSearch() {
            if (this.name == '') {
                this.getData();
            }
            console.log(this.name, '商家姓名');
            shopList({
                page: 1,
                pageNum: 10,
                type: 1 ,//商家列表
                name:this.name
            }).then((res) => {
                console.log(res.data, '商家列表');
                this.tableData = res.data.list;
                this.pageTotal =  res.data.count || 50;
            });
        },
        // 查看
        handleEdit(index, row) {
            console.log(index, row);
            shopInfo({
                id: index.id //商家列表
            }).then((res) => {
                this.form = res.data;
                console.log(res.data, '商家详情列表');
            });
            this.editVisible = true;
        },
        //提现比例
        Withdrawal(index, row) {
            console.log(index, row);
            this.shopId = index.id
            this.Withdrawalshow = true;
        },
        //美团参数设置
        Parameter(index, row){
            // console.log(scope,'美团参数')           
            console.log(index, row);
            this.m_shopId = index.id
            this.Parametershow = true;
           
        },
        //美团分页
        ParametersaveEdit(){
            if(this.key==''){
                this.$message.error(`请输入key`);
                return
            }
            if(this.secret==''){
                this.$message.error(`请输入secret`);
                return
            }
            this.Parametershow = false;
            setMtKey({
                shopId:this.m_shopId, 
                secret: this.secret,
                key:this.key,
            }).then((res) => {
                console.log(res)
                if(res.code == 0){
                    this.$message.success(`设置成功`);
                }
            });
        },
        //商家授权
        Accredit(scope){
            let url = 'https://gongxiangtaiqiu.axa2.com/shopAuth?shopId=' +scope.id
            window.location.href = url;
        },
        shopsaveEdit(){
            if(this.ratio>1){
                this.$message.error(`请输入0~1之间的小数`);
                return
            }
            this.Withdrawalshow = false;
            setShopWithdrawalScale({
                shopId: this.shopId, 
                withdrawalScale: this.ratio
            }).then((res) => {
                console.log(res,this.shopId,this.ratio)
                if(res.code == 0){
                    this.$message.success(`设置成功`);
                }
                this.getData()
            });
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'page', val);
            this.getData();
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.green {
    color: rgb(38, 141, 38);
}
.red {
    color: red;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    /* margin: auto; */
    width: 40px;
    height: 40px;
}
</style>
